package com.heima.article.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.article.service.ApAuthorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@Api(value = "app作者管理API", tags = "app作者管理API")
@RestController
@RequestMapping("/api/v1/author")
public class ApAuthorController {
    private ApAuthorService apAuthorService;

    @ApiOperation(value = "作者查询", notes = "根据得到的ID查询关联的作者信息")
    @GetMapping("/findByUserId/{id}")
    public ResponseResult<ApAuthor> findByUserId(@PathVariable("userId") Integer userId) {
        return ResponseResult.okResult(apAuthorService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getId, userId)));
    }

    @ApiOperation(value = "保存作者", notes = "保存作者信息")
    @PostMapping("/save")
    public ResponseResult add(@RequestBody ApAuthor apAuthor) {
        apAuthorService.save(apAuthor);
        return ResponseResult.okResult();
    }
}
